package com.century.sjt.activity.order;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.century.sjt.R;
import com.century.sjt.activity.BaseActivity;
import com.century.sjt.adapter.MerchantOrderDetailsAdapter;
import com.century.sjt.entity.ChangeOrderInfo;
import com.century.sjt.entity.MyOrderInfo;
import com.century.sjt.util.Constant;
import com.century.sjt.util.TipUtil;
import com.century.sjt.utils.PreferenceManager;
import com.century.sjt.widget.CustomDialog;
import com.century.sjt.widget.TitleBar.SjtTitleBar;
import com.century.sjt.widget.svpprogresshud.SVProgressHUD;

import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 *  商家订单详情
 */
public class MerchantOrderDetailActivity extends BaseActivity implements View.OnClickListener {
    @BindView(R.id.my_order_details_title)
    SjtTitleBar titleBar;
    @BindView(R.id.tv_order_time)
    TextView orderTime;
    @BindView(R.id.tv_order_status)
    TextView orderStatus;
    @BindView(R.id.tv_order_total)
    TextView orderTotal;
    @BindView(R.id.tv_discount)
    TextView diacount;
//    @BindView(R.id.tv_discount_total)
//    TextView discountTotal;
    @BindView(R.id.tv_order_id)
    TextView  tv_order_id;
    @BindView(R.id.item_tv_name)
    TextView consignee;
    @BindView(R.id.item_tv_phome)
    TextView consigneePhone;
    @BindView(R.id.item_tv_address)
    TextView consigneeAddress;
    @BindView(R.id.tv_change_address)
    TextView tvIcon;
    @BindView(R.id.ll_order_btn)
    LinearLayout ll_order_btn;
    @BindView(R.id.btn_ok)
    Button btn_ok;
    @BindView(R.id.btn_no)
    Button btn_no;
    @BindView(R.id.btn_return)
    Button btn_return;
    @BindView(R.id.ll_discount)
    LinearLayout ll_discount;
    @BindView(R.id.tv_isvip)
    TextView tv_isvip;
    @BindView(R.id.ll_returnAmount)
    LinearLayout ll_returnAmount;
    @BindView(R.id.tv_returnAmount)
    TextView tv_returnAmount;
    @BindView(R.id.tv_return_icon)
    TextView tv_return_icon;
    @BindView(R.id.ll_logistics_information)
    LinearLayout ll_logistics_information;
    @BindView(R.id.ll_chang_address)
    LinearLayout changAddress;


    @BindView(R.id.ll_exchange_rate)//汇率为1时隐藏
    LinearLayout ll_exchange_rate;
    @BindView(R.id.ll_home_currency)
    LinearLayout ll_home_currency;
    @BindView(R.id.tv_total_type)
    TextView totalType;
//    @BindView(R.id.tv_money_type)
//    TextView moneyType;
    @BindView(R.id.tv_domestic_currency)
    TextView  tv_domestic_currency;
    @BindView(R.id.tv_home_currency)
    TextView homeCurrency;
    @BindView(R.id.home_currency_type)
    TextView  homeCurrencyType;
    @BindView(R.id.tv_exchange_rate)//汇率
    TextView tv_exchange_rate;

    private List<MyOrderInfo> goodsList = new ArrayList<>();
    private Context mContext;
    private SVProgressHUD mSVProgressHUD;
    private Handler mHandler;
    private MerchantOrderDetailsAdapter adapter;
    private ListView mListView;
    private SwipeRefreshLayout mSwipeLayout;//刷新组件

    CustomDialog.Builder builder;
    ChangeOrderInfo mInfo = new ChangeOrderInfo();

    private String Status = "0";//判断订单状态

    private String orderId;

    private static String returnGoodConfirm = Constant.returnGoodConfirm;//退货（ 0:拒绝  1：同意   2：取消）
    private static String orderRefundConfirm = Constant.orderRefundConfirm;//退款（ 0:申请  1：同意   2：取消）

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_merchantorder_details);
        ButterKnife.bind(this);

        mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case 1:
                        adapter.notifyDataSetChanged();
                        TipUtil.closeProgressDialog();
                        mSwipeLayout.setRefreshing(false);
                        break;
                    case 2:
                        goodsList.clear();
                        orderDetails(orderId);
                        break;
                    case 3:
//                        if(isDataChangeOk) {
//                            mSwipeLayout.setRefreshing(true);
//                            iCurrPage++;
//                            getRecords();
//                        }
                        break;
                }
            }
        };
        initView();
        initEvent();
        initData();
    }

    @Override
    protected void onResume() {
//        Message msg = new Message();
//        msg.what = 2;
//        mHandler.sendMessage(msg);
        super.onResume();
    }

    @Override
    protected void initView() {
        mSVProgressHUD = new SVProgressHUD(this);
        mContext = this;
        builder = new CustomDialog.Builder(this);
        Typeface iconfont = Typeface.createFromAsset(getAssets(), "iconfont.ttf");
        tvIcon.setTypeface(iconfont);
        tv_isvip.setTypeface(iconfont);
        tv_return_icon.setTypeface(iconfont);
        titleBar.setLeftIconResource(getResources().getString(R.string.icon_return));
        titleBar.setLeftLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mListView = (ListView) findViewById(R.id.my_order_details_lv);
        mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.activity_list_refesh);
    }

    @Override
    protected void initEvent() {

        ll_order_btn.setOnClickListener(this);
        btn_no.setOnClickListener(this);
        btn_ok.setOnClickListener(this);
        btn_return.setOnClickListener(this);
        ll_logistics_information.setOnClickListener(this);

        adapter = new MerchantOrderDetailsAdapter(MerchantOrderDetailActivity.this, goodsList, mHandler);

        mListView.setAdapter(adapter);


        //刷新组件
        mSwipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                Message msg = new Message();
                msg.what = 2;
                mHandler.sendMessage(msg);
            }
        });
        mSwipeLayout.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light,
                android.R.color.holo_orange_light, android.R.color.holo_red_light);
    }

    @Override
    protected void initData() {
        Intent intent = getIntent();
        orderId = intent.getStringExtra("orderId");
        Status = intent.getStringExtra("status");
        orderStatusJudge(Status);
        orderDetails(orderId);
    }

    /**
     * 订单详情
     */
    private void orderDetails(final String orderId) {
        mSVProgressHUD.showWithStatus(getResources().getString(R.string.jiazaizhong));
        StringRequest stringRequest = new StringRequest(Request.Method.POST, Constant.orderDetails, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                try {

                    TipUtil.log("接口返回", response, 1);
                    JSONTokener jsonParser = new JSONTokener(response);
                    JSONObject res = (JSONObject) jsonParser.nextValue();
                    String code = res.getString("code");
                    String message = res.getString("message");
                    if (code.equals("200")) {
                        JSONObject data = res.getJSONObject("data");
                        JSONObject receiver = data.getJSONObject("receiver");
                        mInfo.setOrderId(data.getString("orderId"));
                        mInfo.setShopId(data.getString("shopId"));
                        mInfo.setShopName(data.getString("shopName"));
                        mInfo.setUserId(data.getString("userId"));
                        mInfo.setDiscount(data.getString("discount"));
                        mInfo.setOrderAmount(data.getString("orderAmount"));
                        mInfo.setDiscountAmount(data.getString("discountAmount"));
                        mInfo.setSettleAmount(data.getString("settleAmount"));
                        mInfo.setStatus(data.getString("status"));
                        mInfo.setStatusName(data.getString("statusName"));
                        mInfo.setIsVIP(data.getString("isVip"));
                        mInfo.setOrderTime(data.getString("orderTime"));
                        mInfo.setReturnAmount(data.getString("returnAmount"));
                        mInfo.setRememberQuantity(data.getString("returnQuantity"));
                        mInfo.setConsignee(receiver.getString("consignee"));
                        mInfo.setPhone(receiver.getString("phone"));
                        mInfo.setAddress(receiver.getString("address"));
                        mInfo.setOrderType(data.getString("orderType"));
                        mInfo.setShippingNumber(data.getString("shippingNumber"));

                        mInfo.setOrderCurrency(data.getString("orderCurrency"));
                        mInfo.setOrderCurrencyName(data.getString("orderCurrencyName"));
                        mInfo.setSettleCurrency(data.getString("settleCurrency"));
                        mInfo.setSettleCurrencyName(data.getString("settleCurrencyName"));
                        mInfo.setRemarks(data.getString("remarks"));
                        mInfo.setExtendInfo(data.getString("extendInfo"));
                        mInfo.setShippingCompanyCode(data.getString("shippingCompanyCode"));
                        mInfo.setShippingCompanyName(data.getString("shippingCompanyName"));
                        mInfo.setExRate(data.getString("exRate"));



                        setTV(mInfo);
                        orderStatusJudge(data.getString("status"));//判断订单状态

                        JSONArray myOrderListist = data.getJSONArray("goodList");
                        for (int i = 0; i < myOrderListist.length(); i++) {
                            JSONObject aData = (JSONObject) myOrderListist.get(i);
                            MyOrderInfo info = new MyOrderInfo();
                            info.setUnitPrice(aData.getString("price"));
                            info.setImage(aData.getString("mainImageUrl"));
                            info.setTotal(aData.getString("amount"));
                            info.setGoodsQuantity(aData.getString("quantity"));
                            info.setRememberQuantity(aData.getString("quantity"));
                            info.setGoodId(aData.getString("goodId"));
                            info.setGoodsName(aData.getString("goodsName"));
                            info.setReturnQuantity(aData.getString("returnQuantity"));
                            info.setReturnAmount(aData.getString("returnAmount"));
                            info.setStatus(data.getString("status"));

                            info.setCurrency(aData.getString("currency"));
                            info.setExtendInfo(aData.getString("extendInfo"));
                            info.setRemarks(aData.getString("remarks"));
                            info.setGoodsDesc(aData.getString("goodsDesc"));
                            info.setOriginalPrice(aData.getString("originalPrice"));

                            goodsList.add(info);
                        }

                    } else {
                        TipUtil.showToast(message, MerchantOrderDetailActivity.this, 1);
                    }

                } catch (Exception ex) {
                    ex.printStackTrace();
                    TipUtil.showToast(getResources().getString(R.string.error_service), MerchantOrderDetailActivity.this, 1);
                }
                mSVProgressHUD.dismiss();
                Message msg = new Message();
                msg.what = 1;
                mHandler.sendMessage(msg);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                TipUtil.showToast(getResources().getString(R.string.error_network), MerchantOrderDetailActivity.this, 1);
                mSVProgressHUD.dismiss();

            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> map = new HashMap<String, String>();
                SharedPreferences mainSharedPreferences = getSharedPreferences(Constant.TAG, Activity.MODE_PRIVATE);
                String userId = mainSharedPreferences.getString("userId", "");
                map.put("loginId", userId);
                map.put("orderId", orderId);
                return map;
            }

            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                SharedPreferences mainSharedPreferences = getSharedPreferences(Constant.TAG, Activity.MODE_PRIVATE);
                String cookie = mainSharedPreferences.getString("cookie", "");
                String rememberMeValue = mainSharedPreferences.getString("rememberMe", "");
                HashMap localHashMap = new HashMap();
                String cookieValue = cookie + ";" + rememberMeValue;
                localHashMap.put("Cookie", cookieValue);
                return localHashMap;
            }
        };
        mQueue.add(stringRequest);
    }

    /**
     * 订单状态判断
     *
     */

    private void orderStatusJudge(String status) {
        Log.d("Tag","订单状态"+status);
        switch (status) {
            case "0"://已撤销
                btn_return.setVisibility(View.VISIBLE);
                ll_order_btn.setVisibility(View.GONE);
                ll_returnAmount.setVisibility(View.GONE);
                btn_return.setText(getResources().getString(R.string.btn_close));
                break;
            case "1"://待支付
                btn_return.setVisibility(View.VISIBLE);
                ll_order_btn.setVisibility(View.GONE);
                ll_returnAmount.setVisibility(View.GONE);
                btn_return.setText(getResources().getString(R.string.btn_close));
                ll_logistics_information.setVisibility(View.GONE);
                break;
            case "2"://已支付（待发货）
                Status="2";
                ll_order_btn.setVisibility(View.GONE);
                btn_return.setVisibility(View.VISIBLE);
                ll_returnAmount.setVisibility(View.GONE);
                btn_return.setText(getResources().getString(R.string.btn_send_out_goods));
                ll_logistics_information.setVisibility(View.GONE);
                break;
            case "3"://已发货（待结算）
                btn_return.setVisibility(View.VISIBLE);
                ll_order_btn.setVisibility(View.GONE);
                ll_returnAmount.setVisibility(View.GONE);
                btn_return.setText(getResources().getString(R.string.btn_close));
                ll_logistics_information.setVisibility(View.VISIBLE);
                break;
            case "5"://退货中
                btn_return.setVisibility(View.GONE);
                ll_order_btn.setVisibility(View.VISIBLE);
                ll_returnAmount.setVisibility(View.VISIBLE);
                btn_no.setText(getResources().getString(R.string.btn_refuse_goods_rejected));
                btn_ok.setText(getResources().getString(R.string.btn_agree_goods_rejected));
                ll_logistics_information.setVisibility(View.VISIBLE);
                break;

            case "6"://已退货
                ll_returnAmount.setVisibility(View.VISIBLE);
                ll_logistics_information.setVisibility(View.VISIBLE);
                ll_order_btn.setVisibility(View.GONE);
                btn_return.setVisibility(View.VISIBLE);
                btn_return.setText(getResources().getString(R.string.btn_close));
                break;
            case "7"://退款中
                ll_returnAmount.setVisibility(View.VISIBLE);
                btn_return.setVisibility(View.GONE);
                ll_order_btn.setVisibility(View.VISIBLE);
                btn_no.setText(getResources().getString(R.string.btn_refuse_goods_refund));
                btn_ok.setText(getResources().getString(R.string.btn_agree_goods_refund));
                ll_logistics_information.setVisibility(View.VISIBLE);
                break;
            case "8"://已退款
                ll_returnAmount.setVisibility(View.VISIBLE);
                ll_logistics_information.setVisibility(View.VISIBLE);
                ll_order_btn.setVisibility(View.GONE);
                btn_return.setVisibility(View.VISIBLE);
                btn_return.setText(getResources().getString(R.string.btn_close));
                break;
            default:
                btn_return.setVisibility(View.VISIBLE);
                ll_order_btn.setVisibility(View.GONE);
                ll_returnAmount.setVisibility(View.GONE);
                btn_return.setText(getResources().getString(R.string.btn_close));
                ll_logistics_information.setVisibility(View.VISIBLE);
                break;
        }
    }


    private void setTV(ChangeOrderInfo mInfo) {
        Status = mInfo.getStatus();
        titleBar.setTitle(mInfo.getShopName());
        orderTime.setText(mInfo.getOrderTime());
        orderStatus.setText(mInfo.getStatusName());
        if (mInfo.getOrderAmount().equals("null")) {
            orderTotal.setText("");
        } else {
            orderTotal.setText(mInfo.getOrderAmount());
        }
        if (mInfo.getReturnAmount().equals("null")){
            tv_returnAmount.setText("");
        }else {
            tv_returnAmount.setText(mInfo.getReturnAmount());
        }
//        discountTotal.setText(mInfo.getDiscountAmount());
        //homeCurrency.setText(mInfo.getSettleAmount());
        if (mInfo.getConsignee().equals("null")) {
//            consignee.setText(getResources().getString(R.string.text_chonse_address));
        } else {
            consignee.setText(mInfo.getConsignee());
        }
        if (mInfo.getPhone().equals("null")) {
            consigneePhone.setText("");
        } else {
            consigneePhone.setText(mInfo.getPhone());
        }
        if (mInfo.getAddress().equals("null")) {
            consigneeAddress.setText("");
        } else {
            consigneeAddress.setText(mInfo.getAddress());
        }
        tv_order_id.setText(mInfo.getOrderId());
        String languageCode = PreferenceManager.getInstance().getLanguageCode();
        if ("zh-CN".equals(languageCode)) {//中文折扣显示
            if (mInfo.getDiscount() != null) {
                if (mInfo.getDiscount().equals("10")) {
                    ll_discount.setVisibility(View.GONE);
                } else {
                    ll_discount.setVisibility(View.VISIBLE);
                    if (mInfo.getIsVIP().equals("1")) {
                        diacount.setText(mInfo.getDiscount()+getResources().getString(R.string.text_discounted));
                        tv_isvip.setVisibility(View.VISIBLE);
                        Typeface iconfont = Typeface.createFromAsset(getAssets(), "iconfont.ttf");
                        tv_isvip.setTypeface(iconfont);
                    } else {
                        tv_isvip.setVisibility(View.GONE);
                        diacount.setText(mInfo.getDiscount()+getResources().getString(R.string.text_discounted));
                    }
                }
            }
        }else {
            if (mInfo.getDiscountDeduct() != null) {
                if (mInfo.getDiscountDeduct().equals("0")) {
                    ll_discount.setVisibility(View.GONE);
                } else {
                    ll_discount.setVisibility(View.VISIBLE);
                    if (mInfo.getIsVIP().equals("1")) {
                        diacount.setText(mInfo.getDiscountDeduct()+getResources().getString(R.string.text_discountDeduct));
                        tv_isvip.setVisibility(View.VISIBLE);
                        Typeface iconfont = Typeface.createFromAsset(getAssets(), "iconfont.ttf");
                        tv_isvip.setTypeface(iconfont);
                    } else {
                        tv_isvip.setVisibility(View.INVISIBLE);
                        diacount.setText(mInfo.getDiscountDeduct()+getResources().getString(R.string.text_discountDeduct));
                    }
                }
            }
        }
        if (mInfo.getOrderType().equals("0")) {
            //普通订单
            changAddress.setVisibility(View.VISIBLE);
            ll_logistics_information.setVisibility(View.VISIBLE);
        } else if (mInfo.getOrderType().equals("1")) {
            //翻译订单
            changAddress.setVisibility(View.GONE);
            ll_logistics_information.setVisibility(View.GONE);
        }
        if (mInfo.getShippingNumber().equals("null")|mInfo.getShippingNumber() == null) {
            ll_logistics_information.setEnabled(false);
        } else {
            ll_logistics_information.setEnabled(true);
        }

        if (mInfo.getExRate().equals("1.0000")){
            ll_exchange_rate.setVisibility(View.GONE);
            ll_home_currency.setVisibility(View.GONE);
        }else{
            ll_exchange_rate.setVisibility(View.VISIBLE);
            ll_home_currency.setVisibility(View.VISIBLE);
        }
        totalType.setText(mInfo.getOrderCurrency());
//        moneyType.setText(mInfo.getOrderCurrency());
        homeCurrency.setText(mInfo.getSettleAmount());
        homeCurrencyType.setText(mInfo.getSettleCurrency());
        tv_exchange_rate.setText(mInfo.getExRate());
        tv_domestic_currency.setText(mInfo.getOrderCurrency()+getResources().getString(R.string.text_pay_currency));
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {

            //拒绝
            case R.id.btn_no:
                if ("5".equals(Status)){//退货
                    ShowToDo(getResources().getString(R.string.error_refuse_goods_rejected),returnGoodConfirm,"0");
                }else if("7".equals(Status)){//退款
                    ShowToDo(getResources().getString(R.string.error_refuse_goods_refund),orderRefundConfirm,"0");
                }
                break;
            //确认
            case R.id.btn_ok:
                if ("5".equals(Status)){//退货
                    ShowToDo(getResources().getString(R.string.error_agree_goods_rejected),returnGoodConfirm,"1");
                }else if("7".equals(Status)){//退款
                    ShowToDo(getResources().getString(R.string.error_agree_goods_refund),orderRefundConfirm,"1");
                }
                break;
            //发货
            case R.id.btn_return:
                if ("2".equals(mInfo.getStatus())) {
                    Intent intent = new Intent();
                    intent.setClass(MerchantOrderDetailActivity.this, MyOrderEnteringMessage.class);
                    intent.putExtra("orderId", orderId);
                    intent.putExtra("type", "inputOrder");
                    startActivity(intent);
                }else {
                    finish();
                }
                break;
            //物流信息
            case R.id.ll_logistics_information:
                String url = "http://www.sf-express.com/mobile/cn/sc/dynamic_functions/waybill/waybill_query_info.html?billno=" +mInfo.getShippingNumber();
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(url)); //这里面是需要调转的rul
                intent = Intent.createChooser(intent, null);
                startActivity(intent);
                break;
        }
    }


    //退货 退款
    private void onMyOrder(final String mQneneURL,final String operate){

        StringRequest stringRequest = new StringRequest(Request.Method.POST, mQneneURL, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                try {
                    TipUtil.log("接口返回", response, 1);
                    JSONTokener jsonParser = new JSONTokener(response);
                    JSONObject res = (JSONObject) jsonParser.nextValue();
                    String code = res.getString("code");
                    String message = res.getString("message");
                    if (code.equals("200")) {//成功

                    } else {//失败
                        TipUtil.showToast(message, mContext, 1);
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                    TipUtil.showToast(mContext.getResources().getString(R.string.error_service), mContext, 1);
                }

                Message msg = new Message();
                msg.what = 2;
                mHandler.sendMessage(msg);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                TipUtil.showToast(mContext.getResources().getString(R.string.error_network), mContext, 1);

                Message msg = new Message();
                msg.what = 2;
                mHandler.sendMessage(msg);
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> map = new HashMap<String, String>();
                SharedPreferences mainSharedPreferences =mContext.getSharedPreferences(Constant.TAG, Activity.MODE_PRIVATE);
                String userId = mainSharedPreferences.getString("userId", "");
                map.put("loginId", userId);
                map.put("orderId", orderId);
                map.put("operate", operate);
                return map;
            }
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                SharedPreferences mainSharedPreferences =mContext. getSharedPreferences(Constant.TAG, Activity.MODE_PRIVATE);
                String cookie = mainSharedPreferences.getString("cookie", "");
                String rememberMeValue = mainSharedPreferences.getString("rememberMe", "");
                HashMap localHashMap = new HashMap();
                String cookieValue = cookie + ";" + rememberMeValue;
                localHashMap.put("Cookie", cookieValue);
                return localHashMap;
            }
        };
        mQueue.add(stringRequest);

    }

    public void ShowToDo(final String message,final String mQneneURL,final String operate){
        AlertDialog.Builder builder = new AlertDialog.Builder(MerchantOrderDetailActivity.this);
        builder.setMessage(message);
        builder.setCancelable(true);
        builder.setNegativeButton(getResources().getString(R.string.btn_no), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        builder.setPositiveButton(getResources().getString(R.string.btn_yes), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                onMyOrder(mQneneURL,operate);
            }
        });
        builder.setCancelable(false);
        builder.create().show();
    }

}
